package com.medi.web.controller.business;

import com.medi.business.domain.vo.DataAuthorizeVo;
import com.medi.business.service.IDataAuthorizeService;
import com.medi.common.annotation.Log;
import com.medi.common.core.controller.BaseController;
import com.medi.common.core.domain.AjaxResult;
import com.medi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 数据权限-数据权限规则管理Controller
 *
 * @author medi
 * @date 2024-09-13
 */
@Api(tags = "后台管理-数据权限过滤规则管理")
@RestController
@RequestMapping("/business/dataAuthor")
public class DataAuthorizeController extends BaseController {
    @Autowired
    private IDataAuthorizeService dataAuthorizeService;


    /**
     * 数据权限-数据权限过滤规则明细
     */
    @ApiOperation("数据权限-数据权限过滤规则明细")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") String relationId) {
        DataAuthorizeVo dataAuthorizeVo = dataAuthorizeService.selectDataAuthorizeVoById(relationId);
        return success(dataAuthorizeVo);
    }

    /**
     * 新增数据权限-过滤条件
     */
    @ApiOperation("数据权限-新增数据权限-过滤条件")
    @Log(title = "数据权限-数据权限过滤规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataAuthorizeVo dataAuthorizeVo) {
        return toAjax(dataAuthorizeService.insertDataAuthorize(dataAuthorizeVo));
    }

    /**
     * 修改数据权限-过滤条件
     */
    @ApiOperation("数据权限-更新数据权限-过滤条件")
    @Log(title = "数据权限-数据权限过滤规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataAuthorizeVo dataAuthorizeVo) {
        return toAjax(dataAuthorizeService.updateDataAuthorize(dataAuthorizeVo));
    }

    /**
     * 删除数据权限-过滤条件
     */
    @ApiOperation("数据权限-删除数据权限-过滤条件")
    @Log(title = "数据权限-过滤条件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(dataAuthorizeService.deleteDataAuthorizeById(id));
    }


}
